package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.NetworkSubjectDisposition;
import com.ruoyi.logistic.domain.NetworkSubjectFirst;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkSubjectDispositionSearchVo;
import com.ruoyi.logistic.service.INetworkSubjectDispositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/subject")
@RestController
@Api(tags = "网点财务_科目配置")
public class NetworkSubjectDispositionController {
    @Autowired
    private INetworkSubjectDispositionService networkSubjectDispositionService;
    @ApiOperation("显示科目配置列表")
    @GetMapping("/selectAll")
    public R selectNetworkSubjectDispositionAll(PageDate pageDate){
        List<NetworkSubjectDisposition> networkSubjectDispositions = networkSubjectDispositionService.selectAll(pageDate);
        if (networkSubjectDispositions == null || networkSubjectDispositions.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkSubjectDispositions));
        }
    }

    @ApiOperation("搜索科目配置")
    @PostMapping("/search")
    public R search(@RequestBody NetworkSubjectDispositionSearchVo networkSubjectDispositionSearchVo){
        List<NetworkSubjectDisposition> networkSubjectDispositions = networkSubjectDispositionService.search(networkSubjectDispositionSearchVo);
        if (networkSubjectDispositions == null || networkSubjectDispositions.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkSubjectDispositions));
        }
    }

//    @ApiOperation("显示科目配置一级科目列表")
//    @GetMapping("/selectFirstName")
//    public R selectFirstName(){
//        List<NetworkSubjectDisposition> networkSubjectDispositions = networkSubjectDispositionService.selectFirstName();
//        if (networkSubjectDispositions == null || networkSubjectDispositions.size() == 0){
//            return R.fail("暂无数据");
//        }else {
//            return R.ok(networkSubjectDispositions);
//        }
//    }
    @ApiOperation("添加科目配置")
    @PostMapping("/insert")
    public R insertNetworkSubjectDisposition(@RequestBody NetworkSubjectDisposition networkSubjectDisposition){
        if (networkSubjectDisposition.getFirstId() == null || networkSubjectDisposition.getNetworkNameId() == null || networkSubjectDisposition.getSecondName() == null || networkSubjectDisposition.getSecondName().equals("")){
            return R.fail("请输入相应字段");
        }
        Boolean isAdd = networkSubjectDispositionService.insert(networkSubjectDisposition);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改科目配置")
    @PostMapping("/update")
    public R updateNetworkSubjectDisposition(@RequestBody NetworkSubjectDisposition networkSubjectDisposition){
        Boolean isUpdate = networkSubjectDispositionService.update(networkSubjectDisposition);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("显示一级科目下拉列表")
    @GetMapping("/selectSubjectFirst")
    public R selectSubjectFirst(){
        List<NetworkSubjectFirst> networkSubjectFirstList = networkSubjectDispositionService.selectSubjectFirstAll();
        if (networkSubjectFirstList == null || networkSubjectFirstList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(networkSubjectFirstList);
        }
    }
}
